package lyx.tank.engine.logic
{
	import lyx.game.element.GameElement;
	import lyx.game.utils.ILogic;
	import lyx.tank.element.Bullet;
	import lyx.tank.element.Tank;
	import lyx.tank.element.Wall;

	public class BulletLogic implements ILogic
	{
		public function handle(interval:int,element:GameElement,game_elements:Array):void
		{
			if(element.life==0)
			{
				return;
			}
			
			var bullet:Bullet = element as Bullet;
			
			bullet.move(interval);
			
			for each(var item:GameElement in game_elements)
			{
				if(bullet==item || item.life==0 )
				{
					continue;
				}
				if((item is Bullet) && (item as Bullet).shooter_type==bullet.shooter_type)
				{
					continue;
				}
				if((item is Tank) && (item as Tank).type==bullet.shooter_type)
				{
					continue;
				}
				
				var is_hit:Boolean = bullet.hitTest(item);
				if(is_hit)
				{
					bullet.life = 0;
					item.life -= 1;
				}
				
			}
		}
	}
}